﻿// --------------------------------
// <copyright file="MemberViewerTest.cs" company="Pattern Web Solutions">
//     Copyright © Simon Gill 2010. Distributed under the GPL.
// </copyright>
// <author>Simon Gill</author>
// ---------------------------------
// This file is part of LeagueManager.Tests

// LeagueManager.Tests is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.

// LeagueManager.Tests is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with LeagueManager.Tests.  If not, see <http://www.gnu.org/licenses/>.

namespace LeagueManager.Tests
{
    using System;
    using System.Windows.Forms;
    using LeagueManager;
    using LeagueManager.Models;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// This is a test class for MemberViewerTest and is intended
    /// to contain all MemberViewerTest Unit Tests
    /// </summary>
    [TestClass()]
    public class MemberViewerTest
    {
        private TestContext testContextInstance;

        /// <summary>
        /// Gets or sets the test context which provides
        /// information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext
        {
            get
            {
                return this.testContextInstance;
            }

            set
            {
                this.testContextInstance = value;
            }
        }

        #region Additional test attributes
         
        // You can use the following additional attributes as you write your tests:
        
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext)
        // {
        // }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup()
        // {
        // }
        //
        // Use TestInitialize to run code before running each test
        // [TestInitialize()]
        // public void MyTestInitialize()
        // {
        // }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup()
        // {
        // }
        #endregion

        /// <summary>
        /// A test for txtNewID_TextChanged
        /// </summary>
        [TestMethod()]
        [DeploymentItem("LeagueManager.exe")]
        [Ignore]
        public void NewID_TextChangedTest()
        {
            PrivateObject param0 = null; // TODO: Initialize to an appropriate value
            MemberViewer_Accessor target = new MemberViewer_Accessor(param0); // TODO: Initialize to an appropriate value
            object sender = null; // TODO: Initialize to an appropriate value
            EventArgs e = null; // TODO: Initialize to an appropriate value
            target.NewID_TextChanged(sender, e);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        /// A test for SetMemberFromControlValues
        /// </summary>
        [TestMethod()]
        [DeploymentItem("LeagueManager.exe")]
        [Ignore]
        public void SetMemberFromControlValuesTest()
        {
            PrivateObject param0 = null; // TODO: Initialize to an appropriate value
            MemberViewer_Accessor target = new MemberViewer_Accessor(param0); // TODO: Initialize to an appropriate value
            target.SetMemberFromControlValues();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        /// A test for SaveAndReloadMembers
        /// </summary>
        [TestMethod()]
        [DeploymentItem("LeagueManager.exe")]
        [Ignore]
        public void SaveAndReloadMembersTest()
        {
            PrivateObject param0 = null; // TODO: Initialize to an appropriate value
            MemberViewer_Accessor target = new MemberViewer_Accessor(param0); // TODO: Initialize to an appropriate value
            object sender = null; // TODO: Initialize to an appropriate value
            EventArgs e = null; // TODO: Initialize to an appropriate value
            target.SaveAndReloadMembers(sender, e);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        /// A test for MarkRecordDirty
        /// </summary>
        [TestMethod()]
        [DeploymentItem("LeagueManager.exe")]
        [Ignore]
        public void MarkRecordDirtyTest()
        {
            PrivateObject param0 = null; // TODO: Initialize to an appropriate value
            MemberViewer_Accessor target = new MemberViewer_Accessor(param0); // TODO: Initialize to an appropriate value
            object sender = null; // TODO: Initialize to an appropriate value
            EventArgs e = null; // TODO: Initialize to an appropriate value
            target.MarkRecordDirty(sender, e);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        /// A test for lstMembers_SelectedIndexChanged
        /// </summary>
        [TestMethod()]
        [DeploymentItem("LeagueManager.exe")]
        [Ignore]
        public void Members_SelectedIndexChangedTest()
        {
            PrivateObject param0 = null; // TODO: Initialize to an appropriate value
            MemberViewer_Accessor target = new MemberViewer_Accessor(param0); // TODO: Initialize to an appropriate value
            object sender = null; // TODO: Initialize to an appropriate value
            EventArgs e = null; // TODO: Initialize to an appropriate value
            target.Members_SelectedIndexChanged(sender, e);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        /// A test for lstGames_ItemCheck
        /// </summary>
        [TestMethod()]
        [DeploymentItem("LeagueManager.exe")]
        [Ignore]
        public void Games_ItemCheckTest()
        {
            PrivateObject param0 = null; // TODO: Initialize to an appropriate value
            MemberViewer_Accessor target = new MemberViewer_Accessor(param0); // TODO: Initialize to an appropriate value
            object sender = null; // TODO: Initialize to an appropriate value
            ItemCheckEventArgs e = null; // TODO: Initialize to an appropriate value
            target.Games_ItemCheck(sender, e);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        /// A test for LoadMembers
        /// </summary>
        [TestMethod()]
        [DeploymentItem("LeagueManager.exe")]
        [Ignore]
        public void LoadMembersTest()
        {
            PrivateObject param0 = null; // TODO: Initialize to an appropriate value
            MemberViewer_Accessor target = new MemberViewer_Accessor(param0); // TODO: Initialize to an appropriate value
            target.LoadMembers();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        /// A test for LoadGames
        /// </summary>
        [TestMethod()]
        [DeploymentItem("LeagueManager.exe")]
        [Ignore]
        public void LoadGamesTest()
        {
            PrivateObject param0 = null; // TODO: Initialize to an appropriate value
            MemberViewer_Accessor target = new MemberViewer_Accessor(param0); // TODO: Initialize to an appropriate value
            target.LoadGames();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        /// A test for InitializeComponent
        /// </summary>
        [TestMethod()]
        [DeploymentItem("LeagueManager.exe")]
        [Ignore]
        public void InitializeComponentTest()
        {
            PrivateObject param0 = null; // TODO: Initialize to an appropriate value
            MemberViewer_Accessor target = new MemberViewer_Accessor(param0); // TODO: Initialize to an appropriate value
            target.InitializeComponent();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        /// A test for GetControlValuesFromMember
        /// </summary>
        [TestMethod()]
        [DeploymentItem("LeagueManager.exe")]
        [Ignore]
        public void GetControlValuesFromMemberTest()
        {
            PrivateObject param0 = null; // TODO: Initialize to an appropriate value
            MemberViewer_Accessor target = new MemberViewer_Accessor(param0); // TODO: Initialize to an appropriate value
            Member member = null; // TODO: Initialize to an appropriate value
            target.GetControlValuesFromMember(member);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        /// A test for Dispose
        /// </summary>
        [TestMethod()]
        [DeploymentItem("LeagueManager.exe")]
        [Ignore]
        public void DisposeTest()
        {
            PrivateObject param0 = null; // TODO: Initialize to an appropriate value
            MemberViewer_Accessor target = new MemberViewer_Accessor(param0); // TODO: Initialize to an appropriate value
            bool disposing = false; // TODO: Initialize to an appropriate value
            target.Dispose(disposing);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        /// Tests that a 7 digit Membership ID cannot be set.
        /// </summary>
        /// <see href="http://gslm.codeplex.com/WorkItem/View.aspx?WorkItemId=7444"/>
        [TestMethod()]
        public void ValidIssue_ClickTest()
        {
            IMembershipRepository repository = new LeagueManager.Tests.Models.ListMembershipRepository();
            MemberViewer_Accessor target = new MemberViewer_Accessor(repository);
            FillDetailsOfUserOne(target);
            target.Add_Click(target, new EventArgs());

            string membershipId = "000001";

            target.txtNewID.Text = membershipId;
            target.Issue_Click(target, new EventArgs());

            Assert.AreEqual(membershipId, (target.lstMembers.Items[1] as Member).MembershipNumber);
        }

        /// <summary>
        /// Tests that a 7 digit Membership ID cannot be set.
        /// </summary>
        /// <see href="http://gslm.codeplex.com/WorkItem/View.aspx?WorkItemId=7444"/>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void InvalidIssueTooLong_ClickTest()
        {
            IMembershipRepository repository = new LeagueManager.Tests.Models.ListMembershipRepository(); // TODO: Initialize to an appropriate value
            MemberViewer_Accessor target = new MemberViewer_Accessor(repository);
            FillDetailsOfUserOne(target);
            target.Add_Click(target, new EventArgs());

            string membershipId = "0000011";

            target.txtNewID.Text = membershipId;
            target.Issue_Click(target, new EventArgs());

            Assert.Fail();
        }

        /// <summary>
        /// A test for MemberViewer Constructor. Tests bug #7140, exception on load with an empty database.
        /// </summary>
        /// <see href="http://gslm.codeplex.com/WorkItem/View.aspx?WorkItemId=7140"/>
        [TestMethod()]
        public void MemberViewerConstructorTest()
        {
            IMembershipRepository repository = new LeagueManager.Tests.Models.EmptyMembershipRepository(); // TODO: Initialize to an appropriate value
            MemberViewer target = new MemberViewer(repository);

            // Passes if there is no exception.
        }

        /// <summary>
        /// A test for MemberViewer Constructor. Tests bug #7181, exception on load with an empty database.
        /// </summary>
        /// <see href="http://gslm.codeplex.com/WorkItem/View.aspx?WorkItemId=7181"/>
        [TestMethod()]
        public void MemberViewerAddFirstMember()
        {
            IMembershipRepository repository = new LeagueManager.Tests.Models.ListMembershipRepository(); // TODO: Initialize to an appropriate value
            MemberViewer_Accessor target = new MemberViewer_Accessor(repository);
            FillDetailsOfUserOne(target);
            target.Add_Click(target, new EventArgs());

            Assert.AreEqual(target.txtName.Text, string.Empty);
            Assert.AreEqual(1, target.lstMembers.Items.Count);
        }

        private static void FillDetailsOfUserOne(MemberViewer_Accessor target)
        {
            target.txtName.Text = "Test User 1";
            target.txtEmail.Text = "email@address.com";
            target.txtPhone.Text = "0121 111 2222";
            target.txtAltPhone.Text = "07999 111 222";
            target.numDay.Value = 1;
            target.numMonth.Value = 1;
            target.numYear.Value = 1990;
            target.txtAddress.Text = "1 Streetname\r\nTownname\r\nCountryname\r\nPostcode";
        }
    }
}
